package com.foo.demo.service.impl;

import com.foo.demo.dao.UserDao;
import com.foo.demo.dao.model.User;
import com.foo.demo.service.IUserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.List;

public class UserServiceImpl implements IUserService {
    private static Logger logger = LogManager.getLogger();
    private UserDao userDao = new UserDao();

    @Override
    public List<User> queryAllUser() {
        logger.info("queryAllUser");
        return userDao.queryAllUser();
    }

    @Override
    public User queryUserByUsername(String username) {
        if (null == username && username.trim().length() < 1) {
            return null;
        }
        return userDao.queryUserByUsername(username);
    }

    @Override
    public int addUser(User user) {
        if (null == user || null == user.getUsername() || null == user.getPassword()) {
            return 0;
        }
        return userDao.addUser(user);
    }

}
